import {SelectProps} from "antd/lib/select";
import React from "react";
import {SysRoleModel} from "@/pages/sys/role/data";
import roleService from "@/pages/sys/role/service";
import {Select} from "antd";
import MultipleSelect from "@/lib/MultipleSelect";
import useLoad from "@/hooks/useLoad";
import {getCurrentUser} from "@/utils/utils";

const {Option} = Select;

const currentUser = getCurrentUser();
/**
 * 当前用户条件下的角色控件
 */
const RoleSelect = function (props: SelectProps<any>) {
  const {data} = useLoad<SysRoleModel[]>({
    onLoad: () => {
      debugger;
      var deptId = currentUser.deptId;
      if (currentUser.admin)
      {
        deptId = "";
      }
      return  roleService.selectList({enableDeptScope: true, name: "", status: true,deptId : deptId})
    }
  }, []);

  return (
    <MultipleSelect {...props}>
      {data && data.map(p => (<Option key={p.id} value={p.id}>{p.name}</Option>))}
    </MultipleSelect>
  );
}

export default RoleSelect;
